package cn.tedu.yl.Patients.controller;

import cn.tedu.yl.Patients.pojo.entity.Patient;
import cn.tedu.yl.Patients.service.PatientService;
import cn.tedu.yl.base.response.JsonResult;
import cn.tedu.yl.base.response.PageData;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "患者模块")
@RestController
@RequestMapping("/v1/patient")
@Slf4j
public class PatientController {
    @Autowired
    private PatientService patientService;

    @GetMapping("selectPatient")
    public JsonResult getAllPatient() {
        log.info("获取所有患者信息");
        PageData allPatient = patientService.getAll();
        return JsonResult.ok(allPatient);
    }

    @PostMapping("createPatient")
    public JsonResult createPatient(@RequestBody Patient patient) {
        log.info("创建患者信息{}", patient);
        patientService.create(patient);
        return JsonResult.ok();
    }

    @PutMapping("updatePatient")
    public JsonResult updateArticle( @RequestBody Patient patient) {
        patientService.update( patient);
        return JsonResult.ok();
    }

    @DeleteMapping("deletePatient/{id}")
    public JsonResult delete(@PathVariable(value = "id") Long id) {
        patientService.delete(id);
        return JsonResult.ok();
    }
}
